package org.jeecg.modules.agriculturalMachinery.service.impl;

import org.apache.shiro.SecurityUtils;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.agriculturalMachinery.entity.AgriculturalMachineryManagement;
import org.jeecg.modules.agriculturalMachinery.mapper.AgriculturalMachineryManagementMapper;
import org.jeecg.modules.agriculturalMachinery.service.IAgriculturalMachineryManagementService;
import org.jeecg.modules.flowable.apithird.business.mapper.FlowMyBusinessMapper;
import org.jeecg.modules.flowable.apithird.entity.approvalProcess;
import org.jeecg.modules.flowable.apithird.service.FlowCommonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.UUID;

/**
 * @Description: 农机管理
 * @Author: jeecg-boot
 * @Date:   2023-09-07
 * @Version: V1.0
 */

@Service
public class AgriculturalMachineryManagementServiceImpl extends ServiceImpl<AgriculturalMachineryManagementMapper, AgriculturalMachineryManagement> implements IAgriculturalMachineryManagementService {
    @Autowired
    AgriculturalMachineryManagementMapper machineryManagementMapper;
    @Autowired
    FlowCommonService flowCommonService;

    @Override
    public int insertAgriculturalMachineryManagement(AgriculturalMachineryManagement machineryManagement) {

        LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        machineryManagement.setUserId(loginUser.getId());
        LocalDate currentDate = LocalDate.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy年MM月dd日");
        machineryManagement.setId(UUID.randomUUID().toString());
        int i = machineryManagementMapper.insertAgriculturalMachineryManagement(machineryManagement);
        flowCommonService.initActBusiness(
                formatter.format(currentDate)+ loginUser.getUsername()+"发起的农机审批流程",
                machineryManagement.getId(),
                "FlowCallBackServiceImpl",
                approvalProcess.Agricultural_machinery_approval,
                approvalProcess.Agricultural_machinery_approvalID );

        return i;
    }
}
